package com.samoilovich.belarustoday.afisha.fragments;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;

import com.samoilovich.belarustoday.R;
import com.samoilovich.belarustoday.afisha.AfishaActivity;
import com.samoilovich.belarustoday.datemodel.CategoryModel;
import com.samoilovich.belarustoday.handlers.AfishaHandler;
import com.samoilovich.belarustoday.basefragments.NewsBaseFragment;
import com.samoilovich.belarustoday.tools.Utility;

public class AfishaMainFragment extends NewsBaseFragment {

    public AfishaMainFragment() {
    }

    public AfishaMainFragment(Context context, String tag) {
        mListItemResId = R.layout.afisha_category_list_item;
        mOnItemClickListener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                CategoryModel category = mAdapter.getItem(position);
                if (position == 0) {
                    ((AfishaActivity) getActivity()).setFilmFragment();
                    return;
                }
                ((AfishaActivity) getActivity()).setEventFragment(category.getType(), category.getName());
            }
        };
        sTitle = R.string.afisha_label;
        mNoImageId = R.drawable.afisha_category_no_image;
        mInProgress = false;
        mWasCreateNormal = true;
        getCategories(context);
    }

    @Override
    protected void getCategories(Context context) {
        super.getCategories(context);
        if (Utility.hasInternetConnection(context)) {
            mInProgress = true;
            AfishaHandler.getInstance().getCategories(this);
        }
    }
}
